from f5_driver.driver_v2 import F5DriverV2
from oslo_log import log as logging


LOG = logging.getLogger(__name__)


class Recreator(object):
    """ Make Driver RPC call"""

    def __init__(self, lbaas_plugin):
        self.lbaas_plugin = lbaas_plugin
        self.f5_driver = F5DriverV2(lbaas_plugin, 'Recreator')

    def recreate_loadbalancer(self, context, resource):
        try:
            self.f5_driver.loadbalancer.recreate(context, resource)
        except Exception as exc:
            LOG.ERROR(
                "Can not recreate loadbalancer %s." %
                resource
            )

    def recreate_listener(self, context, resource):
        try:
            self.f5_driver.listener.recreate(context, resource)
        except Exception as exc:
            LOG.ERROR(
                "Can not recreate listener %s." %
                resource
            )

    def recreate_pool(self, context, resource):
        try:
            self.f5_driver.pool.recreate(context, resource)
        except Exception as exc:
            LOG.ERROR(
                "Can not recreate pool %s." %
                resource
            )

    def recreate_member(self, context, resource):
        try:
            self.f5_driver.member.recreate(context, resource)
        except Exception as exc:
            LOG.ERROR(
                "Can not recreate member %s." %
                resource
            )

    def recreate_healthmonitor(self, resource):
        pass

    def recreate_l7policy(self, resource):
        pass

    def recreate_l7rule(self, resource):
        pass
